/*
 * @Author: yangni 920556271@qq.com
 * @Date: 2023-09-26 15:18:07
 * @LastEditors: yangni 920556271@qq.com
 * @LastEditTime: 2024-05-14 09:33:44
 * @FilePath: /yt-devops/lib/pages/tabs/device_tab/device_tab_view.dart
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:path/path.dart';
import 'package:yt_devops/components/app_bar/app_bar_widget.dart';
import 'package:yt_devops/components/app_permission/auth_tab.dart';
import 'package:yt_devops/components/app_permission/yt_bottom_navigation_bar.dart';
import 'package:yt_devops/components/app_permission/yt_tab_bar_view.dart';
import 'package:yt_devops/components/app_permission/yt_tab_view_model.dart';
import 'package:yt_devops/components/gaps.dart';
import 'package:yt_devops/pages/devices/device_tab/history_info/history_info_view.dart';
import 'package:yt_devops/pages/site/site_setting/siet_elec_price_setting/site_mains_elec_detail/keep_aliver_wrapper.dart';

import 'package:yt_devops/resources/resources.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/styles/styles.dart';
import 'package:yt_devops/utils/constants/permission_page_constant.dart';

import 'device_tab_controller.dart';

class DeviceTabPage extends GetView<DeviceTabController> {
  final String tagName;

  DeviceTabPage({required this.tagName, Key? key}) : super(key: key);

  @override
  String get tag => tagName;

  var bottomBarItems = [
    BottomNavigationBarItem(
      label: ResKey.deviceDetail.tr,
      icon: Image.asset(
        ImageAssets.deviceTabDetailUnselected,
        width: 24.w,
        height: 24.w,
      ),
      activeIcon: Image.asset(
        ImageAssets.deviceTabDetailSelected,
        color: Colour.primaryColor,
        width: 24.w,
        height: 24.w,
      ),
    ),
    BottomNavigationBarItem(
      label: ResKey.alarm.tr,
      icon: Image.asset(
        ImageAssets.deviceTabAlarmUnselected,
        width: 24.w,
        height: 24.w,
      ),
      activeIcon: Image.asset(
        ImageAssets.deviceTabAlarmSelected,
        color: Colour.primaryColor,
        width: 24.w,
        height: 24.w,
      ),
    ),
    BottomNavigationBarItem(
      label: ResKey.deviceHistoricalInformatio.tr,
      icon: Image.asset(
        ImageAssets.deviceTabHistoryUnselected,
        width: 24.w,
        height: 24.w,
      ),
      activeIcon: Image.asset(
        ImageAssets.deviceTabHistoryUnselected,
        width: 24.w,
        height: 24.w,
        color: Colour.primaryColor,
      ),
    ),
    BottomNavigationBarItem(
      label: ResKey.basicInfo.tr,
      icon: Image.asset(
        ImageAssets.deviceTabBasicUnselected,
        width: 24.w,
        height: 24.w,
      ),
      activeIcon: Image.asset(
        ImageAssets.deviceTabBasicUnselected,
        width: 24.w,
        height: 24.w,
        color: Colour.primaryColor,
      ),
    ),
  ];

  @override
  Widget build(BuildContext context) {
    return GetBuilder<DeviceTabController>(
      // id: controller.deviceId,
      init: controller,
      global: false,
      builder: (controller) => controller.permissionGroups.isEmpty
          ? Gaps.empty
          : AuthTab(
              tabList: controller.permissionGroups,
              build: (context, filtes, tabController) {
                var data = AuthTabWidget.of(context).data;
                return Scaffold(
                  body: TabBarView(
                      controller: tabController,
                      children: filtes.map((e) => e.permissionWidget).toList()),
                  bottomNavigationBar: BottomNavigationBar(
                    type: BottomNavigationBarType.fixed,
                    backgroundColor: Colors.white,
                    currentIndex: data.index,
                    onTap: (i) => data.index = i,
                    selectedItemColor: Colour.primaryColor,
                    unselectedItemColor: Colour.lightTextColor,
                    items: filtes
                        .map(
                          (e) => BottomNavigationBarItem(
                            label: e.labelString,
                            icon: Image.asset(
                              e.imageString,
                              width: 24.w,
                              height: 24.w,
                              color: Colour.bottomTabBarColor,
                            ),
                            activeIcon: Image.asset(
                              e.imageString,
                              color: Colour.primaryColor,
                              width: 24.w,
                              height: 24.w,
                            ),
                          ),
                        )
                        .toList(),
                  ),
                );
              },
            ),
    );
  }
}
